package com.bestdo.returndata;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class Client {
	public static void main(String[] args) {
		args = new String[]{"127.0.0.1","8088","12"};
		
		if(args == null || args.length !=3){
			System.err.println("***请输入正确的ip port data参数！***");
			System.exit(0);
		}
		String ip = args[0];
		int port = Integer.parseInt(args[1]);
		String data = args[2];
		
		try {
			 Socket s = new Socket(ip, port);
		 
			 DataInputStream dis = new DataInputStream(s.getInputStream());
	         DataOutputStream dos = new DataOutputStream(s.getOutputStream());
	         dos.writeUTF(data);
			System.out.println("***客户端发送："+data);
			String str = dis.readUTF();
			System.out.println("***服务端返回："+str);
			
			dis.close();
	        dos.close();
			s.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.err.println("***服务失败！***");
			System.exit(0);
		}
		
	}
}
